﻿using MediatR;
using Traceability.APP.Applications.Commands.Suyuan;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure;

namespace Traceability.APP.Applications.CommandHandlers.Suyuan
{
    public class ShopQueryCommandHandler : IRequestHandler<ShopQueryCommand, APIResult<List<ShopModel>>>
    {
        private readonly IBaseRepository<ShopModel> _shopRepository;

        public ShopQueryCommandHandler(IBaseRepository<ShopModel> shopRepository)
        {
            _shopRepository = shopRepository;
        }

        public Task<APIResult<List<ShopModel>>> Handle(ShopQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ShopModel>> result = new APIResult<List<ShopModel>>();
            result.Code = APIEnum.QuerySuccess;
            result.Message = APIEnum.QuerySuccess.Desc();
            var m = _shopRepository.GetAll().ToList();
            result.Data = m;
            return Task.FromResult(result);
        }
    }
}
